<template>
  <div class="box">
    <el-container class="home_container">
      <el-header>
        <div class="head">
          <img src="../assets/tx.jpg" alt />
          <span>商品后台管理系统</span>
        </div>
        <el-button type="info" @click="logout">退出</el-button>
      </el-header>
      <el-container>
        <!-- 侧边栏区域 -->
        <el-aside :width="isCollapse?'60px':'200px'">
            <div class="toggle-button" @click="toggleCollapse">|||</div>
          <el-menu background-color="#545c64" text-color="#fff" active-text-color="#ffd04b" unique-opened :collapse="isCollapse"
           :collapse-transition="false" router>
            <!-- 一级菜单 -->
            <el-submenu :index="item.id+''" v-for="item in this.rou" :key="item.id">
              <template slot="title">
                <i :class="item.ic"></i>
                <span>{{item.name}}</span>
              </template>

            &nbsp;  <el-menu-item
                :index="submmit.path"
                v-for=" submmit in item.children"
                :key="submmit.id"
              >
                <template slot="title">
                  <i class="el-icon-menu"></i>
                  <span>{{submmit.name}}</span>
                </template>
              </el-menu-item>
            </el-submenu>
          </el-menu>
        </el-aside>
        <el-main>
         <!-- <router-view></router-view> -->
          <keep-alive include="getlun">
            <router-view></router-view>
            </keep-alive>
             <!-- <keep-alive>
          <router-view v-if="$route.meta.keepAlive"> -->
            <!-- 这里是会被缓存的视图组件，比如 Home！ -->
          <!-- </router-view>
        </keep-alive>
 
        <router-view v-if="!$route.meta.keepAlive"></router-view> -->

        </el-main>
      </el-container>
    </el-container>
  </div>
</template>
<script>
import rou from './rout.js'
export default {
  data() {
    return {
      rou,
      isCollapse:false,
    }
  },
  created() {
    this.getMenulist()
  },
  methods: {
    logout() {
      window.sessionStorage.clear()
      this.$router.push('/home')
    },
    async getMenulist() {
      // const { data: res } = await this.$http.get(
      //   'http://127.0.0.1:8888/api/private/v1/menus'
      // )
      // console.log(res)
    },
    toggleCollapse(){
        this.isCollapse=!this.isCollapse
    }
  }
}
</script>
<style lang="less" scoped>
.box {
  height: 100%;
}
.home_container {
  height: 100%;
}
.el-header {
  background-color: #373d41;
  display: flex;
  padding-left: 0;
  flex-direction: row;
  justify-content: space-between;
  align-items: center;
  .head {
    display: flex;
    flex-direction: row;
    align-items: center;
    img {
      width: 60px;
      height: 60px;
      border-radius: 50%;
    }
    span {
      color: #fff;
      margin-left: 20px;
    }
  }
}
.el-aside {
  background-color: #333744;
  .el-menu {
    border-right: none;
  }
}
.el-main {
  background-color: #eaedf1;
}
.el-button {
  height: 40px;
}
.el-submenu .el-menu-item{
    padding: 0;
}
.iconfont {
    margin-right: 10px;
}
.toggle-button{
    background-color: #4a5064;
    font-size: 10px;
    line-height: 24px;
    letter-spacing: 0.2em;
    text-align: center;
    cursor: pointer;
    color: #fff;
}
</style>